<template>
  <div>
    <v-card style="width:100%;">
      <v-card-title>
        <h3>{{name}}</h3>
      </v-card-title>
    <v-card-text>
      <v-form ref="searchForm">
      <v-layout row wrap>
        <v-flex xs12 sm4 md2 class="pr-3">
          <v-autocomplete :items="env.items" v-model="env.value" item-text="text" item-value="value" label="环境" :clearable="true" autocomplete ></v-autocomplete>
        </v-flex>
        <v-flex xs12 sm4 md2 class="pr-3">
          <v-autocomplete :items="type.items" v-model="type.value" item-text="text" item-value="value" label="设备类型" :clearable="true" autocomplete ></v-autocomplete>
        </v-flex>
        <v-spacer></v-spacer>
        <v-btn color="primary" @click.stop="serviceSearch" small><h4>查询</h4></v-btn>
      </v-layout>
      </v-form>
      </v-card-text>
    </v-card>
    <p></p>
      <v-card>
        <v-card-title>
          <v-flex xs12 sm12 md5 class="pr-3">
            <newservice></newservice>
            <v-btn dark color="teal" @click.stop="serviceDownload" small><v-icon dark>file_download</v-icon></v-btn>
          </v-flex>
          <v-flex xs12 sm12 md7 class="pr-3">
            <v-text-field append-icon="search" :label="searchLabel" single-line hide-details v-model="search" ></v-text-field>
          </v-flex>
          <editservice :editdialog = "editdialog" :id = "id"></editservice>
        </v-card-title>
          <v-data-table
            :headers="headers"
            :items="items"
            :pagination.sync="pagination"
            :total-items="totalItems"
            :loading="loading"
            :rows-per-page-items="rowsPerPageItems"
            :no-data-text="etext"
            class="elevation-1">
            <template slot="items" slot-scope="props">
               <td class="datastyle" v-for="(value) in headers" :key="value.id" @click.stop="openServiceEdit(props.item)">{{props.item[value.value]}}</td>
            </template>
            <template slot="no-data">
              <v-alert :value="true" color="error" icon="warning">
                {{etext}}
              </v-alert>
            </template>
          </v-data-table>
      </v-card>
  </div>
</template>

<script>
import { createNamespacedHelpers } from 'vuex'
const { mapActions } = createNamespacedHelpers('listservice')

export default {
  data: function () {
    return this.$store.state.listservice
  },
  watch: {
    pagination () {
      this.handlerService()
    },
    search () {
      this.handlerService()
    }
  },
  methods: {
    ...mapActions({
      handlerService: 'handlerService',
      loadServiceFilters: 'loadServiceFilters',
      openServiceEdit: 'openServiceEdit',
      serviceSearch: 'serviceSearch',
      serviceDownload: 'serviceDownload',
      loadServiceHeaders: 'loadServiceHeaders'
    })
  },
  mounted () {
    this.loadServiceFilters()
    this.loadServiceHeaders()
  },
  components: {
    newservice: () => import('../service/newservice'),
    editservice: () => import('../service/editservice')
  }
}
</script>
